#include "cortrolset.h"
#include "ui_cortrolset.h"
#include "controler.h"

cortrolSet::cortrolSet(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::cortrolSet)
{
    ui->setupUi(this);
    // setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
    setFixedSize(this->size());

    connect(ui->save,&QPushButton::clicked,this,[=](){
        Controler::gasInSwitchPort = ui->gasInSwitchPort->text().toInt();
        Controler::gasOutSwitchPort = ui->gasOutSwitchPort->text().toInt();
        Controler::launchSwitchPort = ui->launchSwitchPort->text().toInt();
        Controler::gasAnalogPort = ui->gasAnalogPort->text().toInt();
        Controler::gasCoefficient = ui->gasCoefficient->text().toFloat();
        Controler::zero = ui->zero->text().toFloat();
        Controler::default_ = ui->default_2->text().toFloat();
        Controler::luanchTime = ui->launchTime->text().toInt();

        Controler::kp = ui->Kp->text().toFloat();
        Controler::ki = ui->Ki->text().toFloat();
        Controler::kd = ui->Kd->text().toFloat();

        emit save();
        this->hide();
    });
    connect(ui->cancel,&QPushButton::clicked,this,[=](){this->hide();});
    connect(this,&cortrolSet::WidgetShown,this,&cortrolSet::initsThis);
}

cortrolSet::~cortrolSet()
{
    delete ui;
}
void cortrolSet::openAdmin(bool flag){
    ui->Kd->setEnabled(flag);
    ui->Ki->setEnabled(flag);
    ui->Kp->setEnabled(flag);
    ui->gasInSwitchPort->setEnabled(flag);
    ui->gasOutSwitchPort->setEnabled(flag);
    ui->gasAnalogPort->setEnabled(flag);
    ui->gasCoefficient->setEnabled(flag);
    ui->zero->setEnabled(flag);
    ui->default_2->setEnabled(flag);
    ui->launchSwitchPort->setEnabled(flag);
}

void cortrolSet::initsThis()
{
    ui->gasInSwitchPort->setText(QString::number(Controler::gasInSwitchPort));
    ui->gasOutSwitchPort->setText(QString::number(Controler::gasOutSwitchPort));
    ui->launchSwitchPort->setText(QString::number(Controler::launchSwitchPort));
    ui->gasAnalogPort->setText(QString::number(Controler::gasAnalogPort));
    ui->gasCoefficient->setText(QString::number(Controler::gasCoefficient));
    ui->zero->setText(QString::number(Controler::zero));
    ui->default_2->setText(QString::number(Controler::default_));
    ui->launchTime->setText(QString::number(Controler::luanchTime));

    ui->Kp->setText(QString::number(Controler::kp));
    ui->Ki->setText(QString::number(Controler::ki));
    ui->Kd->setText(QString::number(Controler::kd));

}
